<template>
	<view class="content">
		<u--input v-model="password" border="bottom" :password='true' placeholder="请输入您要修改的密码"></u--input><br>
		<u--input v-model="passwords" border="bottom" :password='true' placeholder="请再次确实密码"></u--input></br>
		
			<u-button shape="circle" @click="() => { if (validatePassword()) backlogin(); }" style="width: 30%;float: left;" color="#ff6600" :hairline="false"
				:throttleTime="2000">返回登录</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				password: '',
				passwords: ''
			}
		},
		methods: {
			backlogin() {
				uni.navigateTo({
					url: '/pages/content/passwordLogin/passwordLogin'
				});
			},
			validatePassword() {
				// 校验密码长度
				if (this.password.length < 8) {
					uni.showToast({
						title: '密码长度至少为8位',
						icon: 'none'
					});
					return false;
				}
				// 校验密码复杂度
				if (!this.isPasswordComplex(this.password)) {
					uni.showToast({
						title: '密码需要包含大写字母、小写字母、数字和特殊字符',
						icon: 'none'
					});
					return false;
				}
				// 校验两次输入的密码是否一致
				if (this.password !== this.passwords) {
					uni.showToast({
						title: '两次输入的密码不一致',
						icon: 'none'
					});
					return false;
				}
				return true;
			},
			isPasswordComplex(password) {
				const regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{6,}$/;
				return regex.test(password);
			}
		}
	}
</script>

<style>
	.content {
		width: 90%;
		margin: auto;
	}
	.content .u-input{
		width: 80%;
	}
	
</style>